package expression;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.boris.expr.Expr;
import org.boris.expr.ExprEvaluatable;
import org.boris.expr.parser.ExprParser;
import org.boris.expr.util.Exprs;
import org.boris.expr.util.SimpleEvaluationContext;

public class TestExpr4j {
    public static void main(String[] args) {
        testExpr4j();
    }
    /**
     * 
     * 
     * @author zhaigx
     * @date 2012-11-16
     */
    private static void testExpr4j() {
        SimpleEvaluationContext context = new SimpleEvaluationContext();
        System.out.println("Expr Evaluator v1.0");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            try {
                System.out.print(">");
                String line = br.readLine();
                if (line == null)
                    break;
                Expr e = ExprParser.parse(line);
                Exprs.toUpperCase(e);
                if (e instanceof ExprEvaluatable) {
                    e = ((ExprEvaluatable) e).evaluate(context);
                }
                System.out.println(e);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    // private static void testExpr4j_2() {
    // DependencyEngine e = new DependencyEngine(new BasicEngineProvider());
    // e.set("B1", "=A1*2");
    // e.set("A1", "=12*2");
    // e.set("C1", "=B1*A1");
    // System.out.println(e.getValue(Range.valueOf("B1")));
    // System.out.println(e.getValue(Range.valueOf("C1")));
    // e.set("A1", "2");
    // System.out.println(e.getValue(Range.valueOf("B1")));
    // System.out.println(e.getValue(Range.valueOf("C1")));
    // }


}
